﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Game.Facade;
using Game.Utils;
using Game.Kernel;
using Game.Entity.Accounts;

namespace Game.Web.Mobile
{
    public partial class RetrieveCheck : UCPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                int typeid = GameRequest.GetFormInt("typeid", 0);
                string content = GameRequest.GetFormString("content");

                if(typeid<=0 || typeid > 2)
                {
                    lbTip.Text = "抱歉，找回密码方式选择错误！";
                    fmStep2.Visible = false;
                    fmStep3.Visible = true;
                    btnSubmit.Visible = false;
                    return;
                }
                if(typeid ==2 && !Utils.Validate.IsPositiveInt(content))
                {
                    lbTip.Text = "抱歉，输入的游戏ID格式错误！";
                    fmStep2.Visible = false;
                    fmStep3.Visible = true;
                    btnSubmit.Visible = false;
                    return;
                }

                Message msg = typeid == 1 ? FacadeManage.aideAccountsFacade.GetUserSecurityByAccounts(content) 
                    : FacadeManage.aideAccountsFacade.GetUserSecurityByGameID(Convert.ToInt32(content));

                if(msg.Success)
                {
                    AccountsProtect protect = msg.EntityList[0] as AccountsProtect;
                    if(protect != null)
                    {
                        lbQuestion1.Text = protect.Question1;
                        lbQuestion2.Text = protect.Question2;
                        lbQuestion3.Text = protect.Question3;
                        hfUser.Value = protect.UserID.ToString();
                    }
                    else
                    {
                        fmStep2.Visible = false;
                        fmStep3.Visible = true;
                    }
                }
                else
                {
                    lbTip.Text = msg.Content;
                    fmStep2.Visible = false;
                    fmStep3.Visible = true;
                    btnSubmit.Visible = false;
                }
            }
        }

        /// <summary>
        /// 增加页面标题
        /// </summary>
        protected override void AddHeaderTitle()
        {
            AddMetaTitle("找回密码重置 - " + ApplicationSettings.Get("title"));
            AddMetaKeywords(ApplicationSettings.Get("keywords"));
            AddMetaDescription(ApplicationSettings.Get("description"));
        }
    }
}